$(document).ready(function() {
	init();
});
	
//默认加载  
function init(){
	//获取信息列表
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/version/versionList",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data,function(i,n){
					var id = n.id;
					var type=typeStr(n.type);
					var status=statusStr(n.status);
					var thislist = 
					'	<tr>'+				
					'		<td>'+(i+1)+'</td>'+
					'		<td>'+type+'</td>'+						
					'		<td>'+n.versionCode+'</td>'+					
					'		<td>'+n.link+'</td>'+
					'		<td>'+status+'</td>'+
					'		<td>'+n.gmtDatetime+'</td>';
					if(n.status==1){
						thislist +=	'		<td>'+
						'           <a class="btn btn-primary btn-xs" href="javascript:;" onclick="deleteeach('+id+')">废弃</a>'+
						'		</td>';	
					}
					thislist +=
					'	</tr>';
					$('#thislist').append(thislist);														
				});
				$('#thiscount').text(data.data.total);				
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});
}

//删除
function deleteeach(id){
	if(confirm("确定要废弃吗？")) {
		deletegq(id);
	}
}

function deletegq(id){
	$.ajax({
		url: urlcore + "/api/version/deleteVersionOne?id="+id,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				location.reload();
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});
}

/**
 * 用户状态返回
 * @param {Object} type
 */
function typeStr(type){
	if(type==1) {
		type = '骑手端';
	}
	else if(type==2) {
		type = '商户端';
	}
	return type;
}


/**
 * 用户状态返回
 * @param {Object} status
 */
function statusStr(status){
	if(status==1) {
		status = '使用';
	}
	else if(status==2) {
		status = '废弃';
	}
	return status;
}



